/*
*    Phantom v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
#pragma once

#ifndef SSI_SOCKETS_API
	#define SSI_SOCKETS_API __declspec(dllexport)
#endif


typedef unsigned int SSI_SOCKET;
typedef unsigned long SSI_ADDR;

#define SSI_SOCKET_SEND 1
#include "SockCmd.h"
#include "winsock.h"


#define SOCKET_VERBOSE_LOG 1
#define SSI_VERBOSE_LOG(x) if(SOCKET_VERBOSE_LOG){CSocketSSI::Log(x);}

//#include <string>
//using std::string;

class SSI_SOCKETS_API CSocketSSI
{
public:
	static int Init(void);
	static SSI_ADDR LookupAddress(const char* pcHost);
	static SSI_SOCKET Connect(SSI_ADDR Address, int Port);
	static int CleanUp(void);
  static int CleanUpSingle(void);
	static CSockCmd SendCommand(SSI_SOCKET InSock, CSockCmd& InCommand);
	static CSockCmd ReadCommand(SSI_SOCKET InSock);
	static int Disconnect(SSI_SOCKET sd);
	static int CloseSocket(SSI_SOCKET sd);
	static SSI_SOCKET Listen(SSI_ADDR Address, int Port);
	static SSI_SOCKET AcceptConnection(SSI_SOCKET InSock, int& Port);
	static char* IPFromSocket(SSI_SOCKET sd);
  static int PortFromSocket(SSI_SOCKET sd);
	static char* IPFromName(const char* Name);
	static void DispLastError(const char* File, int Line);
  static int GetLastError();
	static int GetHostName(char* Buff, int sz);
	static int Log(const char* mess);
	static int ClearLog();
  static int SetLogFile(const char* In);  

	CSocketSSI(void);
	~CSocketSSI(void);
	int SendData(char* Data, int iLen);
	int ReadData(char* Data, int iLen);

	sockaddr_in myAddr;
	SSI_SOCKET myHandle;
	int myPort;

private:
  static char socket_log_file[1024];
  static int do_log;
};
